package bud.web.boardshop.service;

import java.util.List;


import bud.vo.BoardFormDTO;
import bud.vo.BoardshopDTO;
import bud.vo.ReplyshopDTO;
import bud.web.boardshop.dao.IBoardshopDao;
import bud.web.boardshop.dao.IReplyshopDao;

public class BoardshopServiceImpl implements IBoardshopService{

	private IBoardshopDao dao;
	private IReplyshopDao rshDao;
	
	public IBoardshopDao getDao() {
		return dao;
	}
	public void setDao(IBoardshopDao dao) {
		this.dao = dao;
	}
	public IReplyshopDao getRshDao() {
		return rshDao;
	}
	public void setRshDao(IReplyshopDao rshDao) {
		this.rshDao = rshDao;
	}
	
	@Override
	public List<BoardshopDTO> getBoardshopList(BoardFormDTO formDTO) {
		return dao.getBoardshopList(formDTO);
	}

	@Override
	public int getBoardshopCount(BoardFormDTO formDTO) {
		return dao.getBoardshopCount(formDTO);
	}

	@Override
	public BoardshopDTO getBoardshop(Integer bsh_no) {
		return dao.getBoardshop(bsh_no);
	}

	@Override
	public BoardshopResult createBoardshop(BoardshopDTO boardshop) {
		int pk = dao.insertBoardshop(boardshop);
		if(pk>=1) {
			return BoardshopResult.OK;
		}else {
			return BoardshopResult.FAILED;
		}
	}

	@Override
	public BoardshopResult modifyBoardshop(BoardshopDTO boardshop) {
		BoardshopDTO tempBoardshop = dao.getBoardshop(boardshop.getBsh_no());
		if(tempBoardshop==null) {
			return BoardshopResult.FAILED;
		}else {
			if(tempBoardshop.getBsh_pass().equals(boardshop.getBsh_pass())) {
				int result =dao.updateBoardshop(boardshop);
				if(result>0) {
					return BoardshopResult.OK;
				}else {
					return BoardshopResult.FAILED;
				}
			} else {
				return BoardshopResult.INVALIDPASSWORD;
			}
		} 
	}

	@Override
	public BoardshopResult removeBoardshop(BoardshopDTO boardshop) {
		BoardshopDTO tempBoardshop = dao.getBoardshop(boardshop.getBsh_no());
		if(tempBoardshop==null) {
			return BoardshopResult.FAILED;
		}else {
			if(tempBoardshop.getBsh_pass().equals(boardshop.getBsh_pass())) {
				int result =dao.deleteBoardshop(boardshop.getBsh_no());
				if(result>0) {
					return BoardshopResult.OK;
				}else {
					return BoardshopResult.FAILED;
				}
			} else {
				return BoardshopResult.INVALIDPASSWORD;
			}
		} 
	}

	@Override
	public List<ReplyshopDTO> getRshList(BoardFormDTO form) {
		return rshDao.getRshList(form);
	}

	@Override
	public int insertReplyshop(ReplyshopDTO replyshop) {
		return rshDao.insertReplyshop(replyshop);
	}

	@Override
	public int deleteReplyshop(ReplyshopDTO replyshop) {
		return rshDao.deleteReplyshop(replyshop);
	}

	@Override
	public int getRshCount(Integer rsh_ref_key) {
		return rshDao.getRshCount(rsh_ref_key);
	}
}
